package edu.fhsu.csci468;

import javax.swing.event.EventListenerList;
import java.net.Socket;


public class ControlPanel implements Runnable
{

	private EventListenerList listenerList;

	private Socket incoming; 
	
	public ControlPanel(Socket incoming, IControlPanelEventListener toLisen)
	{
		this.incoming = incoming;
		addControlPanelEventListener(toLisen);
	}
	
	public void run()
	{
		
	}
	
	public void addControlPanelEventListener(
			IControlPanelEventListener eventListener)
	{
		listenerList.add(IControlPanelEventListener.class, eventListener);
	}

	public void removeControlPanelEventListener(
			IControlPanelEventListener eventListener)
	{
		listenerList.remove(IControlPanelEventListener.class, eventListener);
	}

	public void removeAllControlPanelEventListeners()
	{
		listenerList = new EventListenerList();
	}

	private void fireControlPanelEvent(ControlPanelEvent event)
	{
		Object[] listeners = listenerList.getListenerList();
		// Each listener occupies two elements - the first is the listener class
		// and the second is the listener instance
		for (int i = 0; i < listeners.length; i += 2)
		{
			if (listeners[i] == IControlPanelEventListener.class)
			{
				((IControlPanelEventListener) listeners[i + 1])
						.controlPanelEventOccurred(event);
			}
		}
	}
}
